<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/18
 * Time: 15:05
 */

namespace app\index\controller;
use app\draw\controller\Draw;
use fileutil\FileUtil;
use think\Db;
use app\index\model\Banner as BannerModel;
class Index
{
    /**
     * 首页
     */
    public function index($member_id = 0)
    {
        writeLogAlipay('funile');
        $banner_list = Db::name('banner')->field('pic_url,jump_link')->where(['status' => 1,'auding_status' => 2,'parent_id' => 7,'is_delete' => 1])->select();
        $news_list = Db::name('news_type')
            ->alias('news_type')
            ->field('news_type.id type_id,news_type.type_name,news.id id,news.title')
            ->where('news_type.auding_status',2)
            ->where('news.auding_status',2)
            ->where('news_type.is_delete',1)
            ->where('news.is_delete',1)
            ->where('news.status',1)
            ->join('news','news_type.id = news.type_id','left')
            ->group('news_type.id')
            ->select();
        $others_bussiness = Db::name('web')->field('id,cat_name,describe,jump_link,pic_url')
            ->where('auding_status',2)
            ->where('parent_id',2)
            ->select();
        $nav = Db::name('single')->field('id,cat_name')->where('parent_id',0)->where('is_delete',1)->select();
        //$member_message = Db::name('member_message')->select();
        $message = Db::name('member_message')->where('type_id',1)->limit(30)->where('message_type',2)->order('id','desc')->field('id,content title')->select()->toArray();
        foreach ($message as &$v){
            $v['title'] = hideStr($v['title'],8,4);
        }
        $ad1 = Db::name('banner')->field('pic_url,jump_link')->where('parent_id',13)->where('auding_status',2)->where('is_delete',1)->select();
        //$ad2 = Db::name('banner')->field('type,pic_url,jump_link')->where('parent_id',1)->where('auding_status',2)->where('is_delete',1)->select();
        $draw_time = (new Draw())->haha();
        $ad2 = Db::name('banner')->field('type,pic_url,jump_link')->where('parent_id',1)->where('auding_status',2)->where('is_delete',1)->select();
        if(!empty($draw_time)){
            $draw_time['type'] = 2;
            $ad2[] = $draw_time;
        }


        if($draw_time){
            $on_off = 'Y';
        }else{
            $on_off = 'N';
        }
        $draw = Db::name('config')->where('varname','web_draw')->value('varvalue');
        $apply_bool = Db::name('config')->where('varname','apply_bool')->value('varvalue');
        $is_click_1_count = Db::name('member_message')->where('member_id',$member_id)->where('is_click',1)->count();
        return ['code' => 200 ,'message' => 'OK',
            'is_click_1_count' => $is_click_1_count,
            'banner_list' => $banner_list,
            'news_list' => $news_list,
            'others_bussiness_list' => $others_bussiness,
            'nav' => $nav,'message_list' => $message,
            'ad1' => $ad1,
            'ad2' => $ad2,
            'draw' => $on_off,
            'apply_bool' => $on_off
        ];
    }



    public function findNum($str=''){
        $str=trim($str);
        if(empty($str)){return '';}
        $reg='/(\d{3}(\.\d+)?)/is';//匹配数字的正则表达式
        preg_match_all($reg,$str,$result);
        if(is_array($result)&&!empty($result)&&!empty($result[1])&&!empty($result[1][0])){
            return $result[1][0];
        }
        return '';
    }


    public function a(){
        halt(json_decode(input('a'),true));
        static $a = 1;
        $a++;
        echo $a;
    }

    public function ji(){
        $find_shop_assignor_records = Db::name('order o')
            ->join('shop_assignor_records sar','o.id = sar.order_id')
            ->where('sar.order_id',397)
            ->find();
        halt($find_shop_assignor_records);
    }

    public function delFileUnderDir($dirName = '../runtime/log')
    {
        (new \FileUtil())->unlinkDir($dirName);
    }


}